import Vue from 'vue'
// 1.引入路由
import VueRouter from 'vue-router'
// 引入使用到的组件...
// 路由组件
import HomePage from '../pages/Home/HomePage'
import SuggestPage from '../pages/Home/SuggestPage'
import UploadPage from '../pages/Upload/UploadPage'
import FindPage from '../pages/Find/FindPage'
import DiscoverPage from '../pages/Find/DiscoverPage'
import UserAttention from '../pages/Friend/friendListValue/UserAttention'
import UserFans from '../pages/Friend/friendListValue/UserFans'
import UserSpace from '../pages/UserSpace/UserSpace'
import UserCollect from '../pages/UserSpace/userSpaceValue/UserCollect'
import UserNode from '../pages/UserSpace/userSpaceValue/UserNode'
import UserLately from '../pages/UserSpace/userSpaceValue/UserLately'
import NodePage from '../pages/Node/NodePage'
import FriendPage from '../pages/Friend/FriendPage'
import NodeAuthorFloat from '../pages/NodeFloating/NodeAuthorFloat'
import AdvertisingOrCompile from "../pages/NodeFloating/AdvertisingOrCompile"
// 懒加载
// import LoginPage from '../pages/Login/LoginPage'
// import NotFindPage from '../pages/NotFindPage'
// import RegisterPage from '../pages/Register/RegisterPage'
// 复用组件
import LeftBar from '../components/LeftBar'
import TopAdvertise from '../components/TopAdvertise'

// 2.使用VueRouter插件
Vue.use(VueRouter)

// 设置路由可以跳转到自己的路径上(刷新页面)
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

// 3.创建路由规则
const routes = [
    {
        path: '/',
        redirect: '/main' // 访问"/"重定位到主页面
    },
    {
        path: '/main', // Home主页面
        components: {
            main: HomePage,
            second: SuggestPage,
            left: LeftBar,
            top: TopAdvertise,
        }
    },
    {
        path: '/main/upload', // 上传页面
        components: {
            main: UploadPage,
            left: LeftBar,
            top: TopAdvertise
        }
    },
    {
        path: '/main/find', // 查找笔记页面
        components: {
            main: DiscoverPage,
            left: LeftBar,
            top: TopAdvertise
        }
    },
    {
        path:'/main/search', // 搜索笔记页面
        components: {
            main: FindPage,
            // left: LeftBar,
            // top: TopAdvertise
        }
    }, 
    {
        path: '/main/friend', // 好友页面
        components: {
            main: FriendPage,
            left: LeftBar,
            top: TopAdvertise
        },
        children: [
            {
                path: 'attention', // 用户的关注子路由
                components: {
                    friendList: UserAttention
                }
            },
            {
                name:'fans',
                path: 'fans', // 用户的粉丝子路由
                components: {
                    friendList: UserFans
                }
            }
        ]
    },
    {
        path: '/main/myNode', // 我的页面
        components: {
            main: UserSpace,
            left: LeftBar,
            top: TopAdvertise
        },
        children: [
            {
                name:'lately',
                path: 'lately', // 最近子路由
                components: {
                    userList: UserLately
                }
            },
            {
                path: 'collect', // 收藏子路由
                components: {
                    userList: UserCollect
                }
            },
            {
                path: 'node', // 作品子路由
                components: {
                    userList: UserNode
                }
            }
        ]
    },
    {
        name:"myMsg",
        path:'/main/myMsg/${id}/${mail}/${sex}/${username}/${description}',
        components:{
            main: () => import('../pages/UserSpace/UserMsg'),
            left: LeftBar,
            top: TopAdvertise
        }
    },
    {
        path: '/login', // 登录页面
        components: {
            main: () => import('../pages/Login/LoginPage')
        }
    },
    {
        path: '/register', // 注册页面
        components: {
            main: () => import('../pages/Register/RegisterPage')
        }
    },
    {
        path: '/nodeDetail', // 笔记页面
        components: {
            main: NodePage,
            float: NodeAuthorFloat,
            floatBehind: AdvertisingOrCompile
        }
    },
    {
        path: '*', // 404页面
        components: {
            main: () => import('../pages/NotFindPage')
        }
    }
]
// 4.创建路由对象，传入规则，并暴露
const router = new VueRouter({
    routes,
    mode: "history" // history模式路由
})
export default router